package com.guli.gulimall.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
//俞鸿宇
@Configuration //项目启动会加载当前类
public class GuliMallCorsConfiguration {

    @Bean
    public CorsWebFilter getcorsWebFilter(){
        // 跨域的配置信息
        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
        // 第一个参数为哪些路径需要处理跨域
        // 具体执行哪些跨域配置
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //1.配置跨域
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.addAllowedOrigin("*");
        //cookie信息
        corsConfiguration.setAllowCredentials(true);

        configurationSource.registerCorsConfiguration("/**",corsConfiguration);

        CorsWebFilter corsWebFilter = new CorsWebFilter(configurationSource);




//        source.registerCorsConfiguration("/**",corsConfiguration);
//        return new CorsWebFilter(source);
        return corsWebFilter;
    }
}
